<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="../../statics/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../statics/css/font.css">
    <link rel="stylesheet" href="../../statics/css/xadmin.css">
    <link rel="stylesheet" href="../../css/metroStyle/metroStyle.css">
    <script src="../../statics/js/jquery.min.js"></script>
    <script src="../../js/jquery.ztree.all.min.js"></script>
    <script type="text/javascript" src="../../statics/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../statics/js/xadmin.js"></script>

</head>

<body>
<div class="x-body">
    <form class="layui-form kinds-add">

        <div class="layui-form-item" style="display: none">
            <label for="id" class="layui-form-label">
                <span class="x-red">*</span>id
            </label>
            <div class="layui-input-inline">
                <input type="text" id="id" name="id" required
                       autocomplete="off" value="" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>


        <div class="layui-form-item">
            <label for="kindsName" class="layui-form-label">
                <span class="x-red">*</span>种类名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="kindsName" name="kindsName"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label for="kindsDesc" class="layui-form-label">
                <span class="x-red">*</span>种类描述
            </label>
            <div class="layui-input-inline">
                <textarea type="text" value="" id="kindsDesc" name="kindsDesc" style="width: 400px;height: 150px"
                          autocomplete="off" class="layui-input"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>是否归还
            </label>
            <div class="layui-input-block">
                <input type="radio" class="radioClass" name="needReback" value="1" title="是" checked>
                <input type="radio" class="radioClass" name="needReback" value="0" title="否">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                添加
            </button>
        </div>
    </form>
</div>
<script>

    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        //监听提交
        form.on('submit(add)', function (data) {
            var registerInfo = $(".kinds-add").serialize();
            registerInfo = decodeURIComponent(registerInfo, true);
            var json = strToJson(registerInfo);
            $.ajax({
                type:"post",
                url:"/kinds/addKindsInfo",
                data:json,
                success:function (result) {
                    if(0===result.code){
                        layer.msg(result.msg,{icon: 1, time: 1000},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(result.msg,{icon: 5, time: 1000});
                    }
                }
            });
            return false;
        });
    });

    function strToJson(data) {
        data = data.replace(/&/g, "\",\"");
        data = data.replace(/=/g, "\":\"");
        data = "({\"" + data + "\"})";
        var obj = eval(data);
        return obj;
    }
</script>
</body>
</html>